'''
bs4基本使用
'''
from bs4 import BeautifulSoup

html = '''
<ul>
    <li><a href="zhangwuji.com">张无忌</a></li>
    <li id="abc"><a href="zhouxingchi.com">周星驰</a></li>
    <li><a href="zhubajie.com">猪八戒</a></li>
    <li><a href="wuzetian.com">武则天</a></li>
</ul>
'''

page = BeautifulSoup(html, 'html.parser')
'''
找一个值
page.find("标签名", attrs={"属性": "值"})

找多个值
page.find_all("标签名", attrs={"属性": "值"})
'''

# <li id="abc"><a href="zhouxingchi.com">周星驰</a></li>
li = page.find('li', attrs={'id': 'abc'})
print(li)

# abc
print(li.get('id'))

# <a href="zhouxingchi.com">周星驰</a>
a = li.find('a')
print(a)

# 周星驰
print(a.text) # 获取文本

#zhouxingchi.com
print(a.get('href')) # 获取属性的值

print('==================================\n')
li_list = page.find_all('li')
for li in li_list:
    a = li.find('a')
    print('{}=={}'.format(a.text, a.get('href')))